home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
protocols
/
generate.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
6KB
|
180 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from interfaces import Protocol, allocate_lock, Interface
from advice import metamethod, supermeta
from api import declareAdapterForProtocol, declareAdapterForType
from api import declareAdapter, adapt
from adapters import NO_ADAPTER_NEEDED
__all__ = [
'protocolForType',
'protocolForURI',
'sequenceOf',
'IBasicSequence',
'URIProtocol',
'TypeSubset',
'WeakSubset',
'ADAPT_SEQUENCE',
'SequenceProtocol']
class URIProtocol(Protocol):
def __init__(self, uri):
self.URI = uri
Protocol.__init__(self)
def __repr__(self):
return 'URIProtocol(%r)' % self.URI
def __reduce__(self):
return (protocolForURI, (self.URI,))
class TypeSubset(Protocol):
def __init__(self, baseType, methods):
self.baseType = baseType
self.methods = methods
Protocol.__init__(self)
def __repr__(self):
return 'TypeSubset(%r,%r)' % (self.baseType, self.methods)
def __reduce__(self):
return (protocolForType, (self.baseType, self.methods, False))
class WeakSubset(TypeSubset, object):
__metaclass__ = type
def __adapt__(self, ob):
result = supermeta(TypeSubset, self).__adapt__(ob)
if result is not None:
return result
for name in self.methods:
if not hasattr(ob, name):
return None
continue
else:
return ob
__adapt__ = metamethod(__adapt__)
def __repr__(self):
return 'WeakSubset(%r,%r)' % (self.baseType, self.methods)
def __reduce__(self):
return (protocolForType, (self.baseType, self.methods, True))
class SequenceProtocol(Protocol):
def __init__(self, baseProtocol):
self.baseProtocol = baseProtocol
Protocol.__init__(self)
def __repr__(self):
return 'sequenceOf(%r)' % self.baseProtocol
def __reduce__(self):
return (sequenceOf, (self.baseProtocol,))
class IBasicSequence(Interface):
def __iter__():
pass
declareAdapter(NO_ADAPTER_NEEDED, provides = [
IBasicSequence], forTypes = [
list,
tuple])
def ADAPT_SEQUENCE(ob, proto):
marker = object()
out = []
proto = proto.baseProtocol
for item in ob:
item = adapt(item, proto, marker)
if item is marker:
return None
out.append(item)
return out
__registryLock = allocate_lock()
registry = { }
def protocolForURI(uri):
__registryLock.acquire()
try:
return registry[uri]
except KeyError:
proto = registry[uri] = URIProtocol(uri)
return proto
finally:
__registryLock.release()
def protocolForType(baseType, methods = (), implicit = False):
methods = []([ (k, k) for k in methods ]).keys()
methods.sort()
methods = tuple(methods)
key = (baseType, methods, not (not implicit))
return __protocolForType(key)
def sequenceOf(baseProtocol):
key = (sequenceOf, baseProtocol)
__registryLock.acquire()
try:
return registry[key]
except KeyError:
proto = registry[key] = SequenceProtocol(baseProtocol)
declareAdapterForProtocol((proto,), (lambda o: ADAPT_SEQUENCE(o, proto)), IBasicSequence)
return proto
finally:
__registryLock.release()
def __protocolForType(key):
__registryLock.acquire()
try:
return registry[key]
except KeyError:
(baseType, methods, implicit) = key
if implicit:
proto = WeakSubset(baseType, methods)
else:
proto = TypeSubset(baseType, methods)
registry[key] = proto
finally:
__registryLock.release()
if implicit:
impliedBy = __protocolForType((baseType, methods, False))
declareAdapterForProtocol(proto, NO_ADAPTER_NEEDED, impliedBy)
declareAdapterForType(proto, NO_ADAPTER_NEEDED, baseType)
return proto